<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div id="app"></div>
</body>
<script>
    // http://zhangpeiyue.com/userList
    const xhr = new XMLHttpRequest();
	xhr.responseType = "json";// 将响应体的数据格式设置为JSON对象
	xhr.open("get","/userList");
	xhr.send();
	xhr.onload = function(){
		document.querySelector("#app").innerHTML = xhr.response.data.map(item=>(`
		    <button onclick="sendVote(${item.id},this)">${item.username}-${item.voteNum}</button>
		`)).join("")
    }
	function sendVote(id,_this){
		const xhr = new XMLHttpRequest();
		xhr.responseType = "json";
		xhr.open("get","/vote/"+id);
		xhr.send();
		xhr.onload = function(){
			const {ok,info,msg} = xhr.response;
			if(ok === 1){
				_this.innerHTML = info.username+"-"+info.voteNum;
			}else{
				alert(msg);
            }

        }
    }
</script>
</html>